import { Module } from '@nestjs/common';
import { RmqService } from './rmq.service';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { BrokerModule } from '@app/rmq/broker/broker.module';
import { BrokerController } from '@app/rmq/broker/broker.controller';

const MQModule = ClientsModule.registerAsync([
    {
      imports: [],
      name: 'USE_FACTORY_CLIENT',
      useFactory: () => ({
        transport: Transport.RMQ,
        options: {
          noAck: false,
          urls: [`amqp://localhost:5672`],
          queue: 'node_queue',
          queueOptions: { durable: false },
          socketOptions: { noDelay: true },
        },
      }),
    },
  ]);

@Module({
  imports: [
    MQModule,
    BrokerModule,
  ],
  controllers: [BrokerController],
  providers: [RmqService],
  exports: [RmqService],
})

export class RmqModule {}
